package yja.gzw.app.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import yja.gzw.app.R
import yja.gzw.app.model.bean.Commenthuifu


class HuifuPinglongAdapter (private val context: Context, private val list: List<Commenthuifu>,private val listener: OnItemClickListener): RecyclerView.Adapter<RecyclerView.ViewHolder>(){

    interface OnItemClickListener {
        fun onItemClick(position: Int, uri: Commenthuifu)
    }

    private var view: View?=null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        view= LayoutInflater.from(parent.context).inflate(R.layout.item_view_huifuplinglong,parent,false)
        Log.e("图片地址展示","走到了2")
        return ViewHodeView(view!!)
    }

    override fun getItemCount(): Int {
       return  list.size
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if(holder is ViewHodeView){
            val requestOptions = RequestOptions.bitmapTransform(CircleCrop())
            Glide.with(context).load("http://117ai.32.hzgqapp.com/"+list[position].user.avatar)
                .apply(requestOptions)
                .into(holder.touxiang)
            holder.nicheng.text=list[position].user.nickname
            holder.neirong.text=list[position].content

            holder.huifu.setOnClickListener {

                listener.onItemClick(position, list[position])
            }
        }


    }

    inner class ViewHodeView(itemView: View):RecyclerView.ViewHolder(itemView){

        var touxiang: ImageView =itemView.findViewById(R.id.touxiang)
        var nicheng: TextView =itemView.findViewById(R.id.nicheng)
        var neirong: TextView =itemView.findViewById(R.id.neirong)
        var huifu: TextView =itemView.findViewById(R.id.huifu)


    }

}